package com.bgs.controller;


import com.bgs.entity.User;
import com.bgs.pojo.CollectionsVo;
import com.bgs.pojo.FootprintVo;
import com.bgs.pojo.UserVo;
import com.bgs.service.UserService;
import com.bgs.tool.R;
import com.tencentyun.TLSSigAPIv2;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.apache.commons.mail.EmailException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    UserService userService;
    @GetMapping("loadcoll/{userId}")
    public R loadcoll(@PathVariable Integer userId){
        List<CollectionsVo> loadcollections = userService.loadcoll(userId);
        return R.ok().data("arr",loadcollections);
    }
    @GetMapping("updatestate/{userId}/{collectionsId}")
    public R updatestate(@PathVariable Integer userId ,@PathVariable Integer collectionsId){
        userService.updatestate(userId,collectionsId);
        return R.ok();
    }
    @GetMapping("loadfoot/{userId}")
    public R loadfoot(@PathVariable Integer userId){
        List<FootprintVo> footprintVos = userService.loadfoot(userId);
        return R.ok().data("arr",footprintVos);
    }
    @GetMapping("updatestates/{userId}/{footprintId}")
    public R updatestates(@PathVariable Integer userId ,@PathVariable Integer footprintId){
        userService.updatestates(userId,footprintId);
        return R.ok();
    }
    @GetMapping("load3/{riderId}")
    public R load3(@PathVariable Integer riderId){
        List<User> user = userService.load3(riderId);
        return R.ok().data("arr3",user);
    }
    @GetMapping("load/{userId}")
        public R load(@PathVariable Integer userId){
        User user = userService.load(userId);
        return R.ok().data("arr",user);
    }
    @GetMapping("hqyzm/{useremail}")
        public R hqyzm (@PathVariable  String useremail) throws EmailException {
        String b = userService.hqyzm(useremail);
        return R.ok().data("email",b);
    }
    @GetMapping("updateemail/{userId}/{userEmail2}")
        public R updateemail(@PathVariable String userId ,@PathVariable String userEmail2){
        userService.updateemail(userId,userEmail2);
        return R.ok();
    }
    @GetMapping("updatepayment/{userId}/{payment1}")
    public R updatepayment(@PathVariable String userId ,@PathVariable String payment1){
        System.out.println("gggggg");
        userService.updatepayment(userId,payment1);
        return R.ok();
    }

    private long expire = 60*60*24*7;


    @Value("${IMConfig.sdkAppId}")
    private long sdkAppId;

    @Value("${IMConfig.secretKey}")
    private String secretKey;


    @GetMapping("/getUserLogon")
    @ApiOperation(value = "骑手登录")
    public R getUserLogon(String phone,String password){
        UserVo userVo = userService.getUserLogon(phone,password);
        TLSSigAPIv2 api = new TLSSigAPIv2(sdkAppId,secretKey);
        String UserSig=api.genSig(String.valueOf(userVo.getUserId()),expire);

        return R.ok().data("userVo",userVo).data("UserSig",UserSig);
    }

}